class Queue:
    def __init__(self):
        self.items=[]
    def enqueue(self,item):
        self.items.append(item)
    def dequeue(self):
        return self.items.pop(0)
    def isEmpty(self):
        return self.items==[]
    def size(self):
        return len(self.items)



def JosephRing(n):
    q = Queue()
    for i in range(1, n + 1):
        q.enqueue(i)
    while q.size() > 1:
        for _ in range(2):
            q.enqueue(q.dequeue())
        q.dequeue()
    return q.dequeue()


while True:
    try:
        n=int(input())
        print(JosephRing(n))

    except:
        break
